clear;
clc;
close all;
addpath('../02_Functions');

%------------------------------------------------------------------------%
% This file creates figure 3 in the paper 
%------------------------------------------------------------------------%


% load ----------------------------------------------------------------------- 

file_name = '../01_data/es_quotes_5minute_EST';


% Call returns routine -----------------------------------------------------------------------

start_date          = datenum(1998,1,5);
finish_date         = datenum(2020,12,29);

winsorizing         = 0;
alpha               = 0.99;
replace_option      = 0;

results             = make_returns_288(file_name,start_date,finish_date,winsorizing,alpha,replace_option);
log_returns         = results.log_return_AD;
T                   = results.T;
caldt_mat           = results.caldt_mat;

% select times --------------------------------------------------------------------------

indx_beg            = find(hour(caldt_mat(1,:)) == 1 & minute(caldt_mat(1,:)) ==0);
indx_fin            = find(hour(caldt_mat(1,:)) == 4 & minute(caldt_mat(1,:)) ==0);
log_returns         = log_returns(:,indx_beg:indx_fin);

% average returns -----------------------------------------------------------------------

mu_log_returns      = 100*252*nanmean(log_returns,1);            

% ---------------------------------------------------------------------------------------

% combine hourly plot and cumulative plot 

index           = 1 : 1 : length(mu_log_returns);
x_ticks         = 1 : 3 : length(mu_log_returns);
x_string        = {'1.00' , '1.15' , '1.30', '1.45' ,'2.00' , '2.15' , '2.30', '2.45' , '3.00','3.15' , '3.30', '3.45' , '4.00'};

lightblue       = [91, 207, 244] / 255; 
lightgrey       = [0.7  0.7  0.7];

figure
b=bar(index, mu_log_returns, 1, 'k');
b.FaceAlpha = 0.5;
b.LineWidth = 1;
ylabel('Ann. hourly avg. log return (in %, bar)')
hold on
xlim([index(1)-0.5 index(end)+0.5])
xtickangle(90)
set(gca,'XTick',x_ticks,'XTickLabel',x_string);
legend off





